/*
 * Created on 24.05.2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package wa.application;

import org.slf4j.LoggerFactory;

/**
 *
 */
public abstract class Application {
	 final org.slf4j.Logger log = LoggerFactory.getLogger(Application.class); 
	 private String[] args;
	 private ApplicationImpl imp;

	 public Application(String[] args, ApplicationImpl imp)
	 {
	 	this.args = args;
	 	this.imp = imp;
	 }
	 
	public int execute() {
		int termCode=AppConst.NORMAL_TERMINATION;
	 	try
		{
    		imp.init(args);
    		imp.preProcess();
    		imp.process();
    		imp.postProcess();
    		termCode = imp.stop();
        } catch (AppException e){
        	log.error("There has been a fatal exception during post process: "+e.getMessage());
        	termCode = AppConst.ABNORMAL_TERMINATION;
		} catch (AppTermination e) {
			termCode = e.getTerminationCode();
		}
		
        return termCode;
	}
	
}
